window.onload=function(){
    changeImg();
    regOrAddCount();
    chooseSpan();
} ;

function changeImg() {
    var smallImgs=document.getElementsByClassName("small-img")[0].getElementsByTagName("img");
    var bigImgs=document.getElementsByClassName("big-img")[0].getElementsByTagName("img");

    for(var i=0;i<smallImgs.length;i++){
        var a=smallImgs[i];
        a.index=i;
        a.onclick=function () {
            for(var j=0;j<smallImgs.length;j++){
                smallImgs[j].className="";
                bigImgs[j].className="";
            }
            this.className="small-show";
            bigImgs[this.index].className="show";
        }
    }
}

function regOrAddCount() {
    var regs=document.getElementsByName("reg");
    var adds=document.getElementsByName("add");
    var nums=document.getElementsByClassName("num");

    for(var i=0;i<regs.length;i++){
        regs[i].index=i;
        adds[i].index=i;
        regs[i].onclick=function () {
            var a=this.index;
            if(parseInt(nums[a].innerHTML)==1){
                return;
            }
            nums[a].innerHTML=parseInt(nums[a].innerHTML)-1;
        };

        adds[i].onclick=function () {
            var a=this.index;
            nums[a].innerHTML=parseInt(nums[a].innerHTML)+1;
        }
    }
}

function chooseSpan() {
    var bustDetail=document.getElementById("bust-detail");
    var cupDetail=document.getElementById("cup-detail");

    var bustSpans=bustDetail.getElementsByTagName("span");
    var cupSpans=cupDetail.getElementsByTagName("span");

    for(var i=0;i<bustSpans.length;i++){
        bustSpans[i].onclick=function () {
            for (var j = 0; j < bustSpans.length; j++) {
                bustSpans[j].style.background = "#eee";
                bustSpans[j].style.color="#333";
            }
            this.style.background = "#ef5e95";
            this.style.color = "#fff";
        }
    }
    for(var i=0;i<cupSpans.length;i++){
        cupSpans[i].onclick=function () {
            for (var j = 0; j < cupSpans.length; j++) {
                cupSpans[j].style.background = "#eee";
                cupSpans[j].style.color="#333";
            }
            this.style.background = "#ef5e95";
            this.style.color = "#fff";
        }
    }
}